CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
PROJECT(libbitcoin-api-cpp)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

# Set compiler settings
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MACOSX_RPATH 1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")

# Set version number
SET(MAJOR_VERSION 0)
SET(MINOR_VERSION 1)
SET(PATCH_VERSION 0)
SET(SO_VERSION    0)

# Add source directory
ADD_SUBDIRECTORY(src/bitcoinapi)

FIND_PACKAGE(Boost COMPONENTS unit_test_framework)
IF(Boost_FOUND)
    ADD_SUBDIRECTORY(src/test)
ENDIF()

# Set package settings
IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
	SET(CPACK_GENERATOR "PackageMaker")
	SET(CPACK_PACKAGING_INSTALL_PREFIX "/opt/local")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
	SET(CPACK_GENERATOR "DEB")
	SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

SET(CPACK_PACKAGE_DESCRIPTION "C++ interface for communication with Bitcoin Wallet.")
SET(CPACK_PACKAGE_VENDOR "Krzysztof Okupski")
SET(CPACK_PACKAGE_CONTACT "Krzysztof Okupski <k.okupski@gmail.com>")
SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")

SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}")

SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})

SET(CPACK_COMPONENTS_ALL bitcoinapi)
INCLUDE(CPack)

# Uninstall target
CONFIGURE_FILE(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)

ADD_CUSTOM_TARGET(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
